<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 * @version    $Id: Controller.php 2011-03-09 08:45:41Z idris $
 * @author     Idris
 */

/**
 * @category   Application_Extensions
 * @package    Vote
 * @copyright  Copyright KEENONWEB LLC
 * @license    http://www.keenonweb.com/
 */

class Vote_Widget_RandomParticipantsController extends Engine_Content_Widget_Abstract
{

  public function indexAction()
  {
		$this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();

    $empty = true;
		$table = Engine_Api::_()->getDbTable('participants', 'vote');
		$params = array(
      'approved' => 1,
      'period' => 'active',
      'not_participated' => $viewer->getIdentity(),
      'not_voted' => $viewer->getIdentity(),
      'ipp' => 1,
      'page' => 1,
      'sort' => 'random',
      'limit' => 1,
      'not_owner' => $viewer->getIdentity()
    );

    $params['type'] = 'photo';
		$this->view->photoPart = $photoPart = $table->getRandomParticipant($params);
    if ($photoPart) {
      $empty = false;
    }

    $params['type'] = 'video';    
		$this->view->videoPart = $videoPart = $table->getRandomParticipant($params);
    if ($videoPart) {
      $empty = false;
    }
    
    $params['type'] = 'music';
		$this->view->musicPart = $musicPart = $table->getRandomParticipant($params);
    if ($musicPart) {
      $empty = false;
    }
    
    if ($empty) {
      return $this->setNoRender();
    }
  }

}